package com.erp.servlet;

import com.erp.bean.Emp;
import com.erp.service.EmpService;
import com.erp.service.impl.EmpServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author zch
 * 添加人员控制器
 */
@WebServlet("/empregist.action")
public class EmpRegistServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //创建员工业务逻辑对象
        EmpService empService = new EmpServiceImpl();
        //接收用户传入的参数
        String name = req.getParameter("name");
        String pass = req.getParameter("pass");
        String tel = req.getParameter("tel");
        String sex = req.getParameter("sex");
        String email = req.getParameter("email");
        String agetr = req.getParameter("age");
        int age = Integer.valueOf(agetr);
        //创建员工对象
        Emp emp = new Emp(name,tel,email,pass,sex,age);
        //调用添加员工方法
        boolean flag = empService.addEmp(emp);
        System.out.println(flag);
        //重定向到员工列表界面
        resp.sendRedirect("emplist.action");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
